package cn.itrip.search.controller;

import cn.itrip.beans.dto.Dto;
import cn.itrip.beans.vo.SearchHotCityVO;
import cn.itrip.search.service.SearchService;
import cn.itrip.search.vo.HotelParam;
import cn.itrip.search.vo.ItripHotelVo;
import cn.itrip.utlis.DtoUtil;
import cn.itrip.utlis.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description :
 * Created by Li on 2020-12-24 14:16:44
 */
@RestController
@RequestMapping("/api/hotellist")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @PostMapping("/searchItripHotelListByHotCity")
    public Dto searchItripHotelListByHotCity(@RequestBody SearchHotCityVO vo){
        try {
            List<ItripHotelVo> list = searchService.searchItripHotelListByHotCity(vo.getCityId()+"", vo.getCount());
            return DtoUtil.returnDataSuccess(list);
        } catch (Exception e) {
            return DtoUtil.returnFail(e.getMessage(),"50001");
        }
    }

    @PostMapping("/searchItripHotelPage")
    public Dto searchItripHotelPage(@RequestBody HotelParam hotelParam){
        try {
            PageBean pageBean = new PageBean();
            pageBean.setCurPage(hotelParam.getPageNo()==null ? 1 : hotelParam.getPageNo());
            pageBean.setPageSize(2);
            searchService.searchItripHotelPage(hotelParam, pageBean);
            return DtoUtil.returnDataSuccess(pageBean);
        } catch (Exception e) {
            return DtoUtil.returnFail(e.getMessage(),"50001");
        }
    }
}
